package com.hoshiicloud.saleorder.controller.refund;


import com.hoshiicloud.common.controller.BaseController;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.saleorder.entity.Consultations;
import com.hoshiicloud.saleorder.service.refund.ConsultationsService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 协商历史(Consultations)表控制层
 *
 * @author qry
 * @since 2019-08-22 11:00:16
 */
@RestController
@RequestMapping("/refund/consultations")
@Slf4j
public class ConsultationsController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ConsultationsService consultationsService;


    @GetMapping("/{id}")
    public Response<Consultations> getById(@PathVariable("id") Long id){
        return Response.data(consultationsService.getConsultationsById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增退款单", notes = "新增退款单")
    public Response<Consultations> save(@RequestBody Consultations entity){
        return  Response.data(consultationsService.saveConsultations(entity));
    }

    @GetMapping("/listByRefundId/{refundId}")
    public Response<List<Consultations>> listByRefundId(@PathVariable("refundId") Long refundId){
        return  Response.data(consultationsService.listByRefundId(refundId));
    }

    @DeleteMapping("/physicsDelete/{refundId}")
    public Response<Boolean> physicsDelete(@PathVariable("refundId") Long refundId ){
        return  Response.data(consultationsService.physicsDelete(refundId));
    }


    @GetMapping("/listByRefundIds")
    @ApiOperation("根据退款单Id集合获取退款协商历史")
    public Response<List<Consultations>> listByRefundIds(@RequestParam("refundIds") List<Long> refundIds){
        if (CollectionUtils.isEmpty(refundIds)) {
            return Response.failed("退款单ID 集合不能为空");
        }
        refundIds.sort(null);
        return Response.data(consultationsService.listByRefundIds(refundIds, StringUtils.join(refundIds, "")));
    }
}
